package cn.znzz.cjm.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {
    //定义邮件队列名字
    public static final String QUEUE_NAME_EMAIL = "queue_name_email";
    //定义短信的队列名字
    public static final String QUEUE_NAME_SMS = "queue_name_sms";
    //站内信队列
    public static final String QUEUE_NAME_SYSTEM_MESSAGE = "queue_name_system_message";
    //定义交换机
    public static final String EXCHANGE_NAME_TOPIC = "exchange_name_topic";

    //交换机
    @Bean(EXCHANGE_NAME_TOPIC)
    public Exchange exchangeNameTopic(){
        return ExchangeBuilder.topicExchange(EXCHANGE_NAME_TOPIC).durable(true).build();
    }
    //邮件
    @Bean(QUEUE_NAME_EMAIL)
    public Queue queueNameEmail(){
        return new Queue(QUEUE_NAME_EMAIL,true);
    }

    //定义短信
    @Bean(QUEUE_NAME_SMS)
    public Queue queueNameSms(){
        return new Queue(QUEUE_NAME_SMS,true);
    }

    //定义内战
    @Bean(QUEUE_NAME_SYSTEM_MESSAGE)
    public Queue queueNameSystemMessage(){
        return new Queue(QUEUE_NAME_SYSTEM_MESSAGE,true);
    }

    //定义短信的队列绑定到交换机
    @Bean
    public Binding smsQueueBinding(@Qualifier(QUEUE_NAME_SMS) Queue smsQueue, Exchange exchangeNameTopic) {
        return BindingBuilder.bind(smsQueue).to(exchangeNameTopic).with("message.sms").noargs();
    }

    //定义邮件绑定交换机
    @Bean
    public Binding emailQueueBinding(@Qualifier(QUEUE_NAME_EMAIL) Queue emailQueue,Exchange exchangeNameTopic){
        return BindingBuilder.bind(emailQueue).to(exchangeNameTopic).with("message.email").noargs();
    }
    //定义站内绑定到交换机
    @Bean
    public Binding systemQueueBinding(@Qualifier(QUEUE_NAME_SYSTEM_MESSAGE) Queue systemQueue,Exchange exchangeNameTopic){
        return BindingBuilder.bind(systemQueue).to(exchangeNameTopic).with("message.system").noargs();
    }
}
